<%@ include file="/taglibs.jsp"%>
<jsp:directive.page import="java.util.Random"/>
<jsp:directive.page import="java.util.Date"/>
<jsp:directive.page import="java.util.Set"/>
<jsp:directive.page import="com.winterwar.base.Event"/>
<jsp:directive.page import="com.winterwar.base.Convention"/>
<%if(session.getAttribute("randFormID") == null){
	Random gen = new Random(new Date().getTime());
	session.setAttribute("randFormID", gen.nextInt() + "");
	
}
%>


<title>Winter War Administration - Edit Registration</title>

<p>Please fill out your information</p>

<html:form action="/wwadmin/registration">
	<input type="hidden" name="method" value="save"/>
	<input type="hidden" name="formID" value="<%=session.getAttribute("randFormID") %>"/>
	<input type="hidden" name="registration.conID" value="${conID }"/>
	<html:hidden property="registration.regID"/>
	<html:select property="registration.userID" onchange="if(this.value == ''){ document.getElementById('userPortion').style.display = 'block';} else {document.getElementById('userPortion').style.display='none';}">
		<html:option value="">New User...</html:option>
		<c:forEach var="user" items="${users}" varStatus="status">
			<html:option value="${user.userID}">${user.lastName}, ${user.firstName}</html:option>
		</c:forEach>
	</html:select><br/>
	<c:choose>
		<c:when test="${userID != '0' }">
			${event.userID}
			${user.firstName } ${user.lastName }<br/>
			${user.address1 }<br/>
			${user.city }, ${user.state } ${user.zipCode }<br/>
			${user.email } ${user.phoneNumber }<br/><br/>
		</c:when>
	</c:choose>
	<input type="hidden" name="user.level" value="1"/>
	<table id="userPortion" <c:choose><c:when  test="${userID != '0' }">style="display:none"</c:when></c:choose>>
		<tr>
			<th><bean:message key="user.firstName"/>: </th>
			<td><html:text property="user.firstName"/></td>
			<th><bean:message key="user.phoneNumber"/>: </th>
			<td><html:text property="user.phoneNumber"/></td>
		</tr>
		<tr>
			<th><bean:message key="user.lastName"/>: </th>
			<td><html:text property="user.lastName"/></td>
			<th><bean:message key="user.email"/>: </th>
			<td><html:text property="user.email"/></td>
		</tr>
		<tr>
			<th><bean:message key="user.address1"/>: </th>
			<td><html:text property="user.address1"/></td>
		</tr>
		<tr>
			<th><bean:message key="user.address2"/>: </th>
			<td><html:text property="user.address2"/></td>
		</tr>
		<tr>
			<th><bean:message key="user.city"/>: </th>
			<td><html:text property="user.city"/></td>
		</tr>
		<tr>
			<th><bean:message key="user.state"/>: </th>
			<td><html:text property="user.state"/></td>
		</tr>
		<tr>
			<th><bean:message key="user.zipCode"/>: </th>
			<td><html:text property="user.zipCode"/></td>
		</tr>
	</table>
	<hr/>
	<table>
		<tr>
			<th><bean:message key="registration.type"/>: </th>
			<td><html:radio property="registration.type" value="1" onclick="document.event.dayRegistered.readonly = false">Single Day</html:radio><br/>
				<html:radio property="registration.type" value="2" onclick="document.event.dayRegistered.readonly = true">Weekend</html:radio><br/>
				<html:radio property="registration.type" value="3" onclick="document.event.dayRegistered.readonly = true">ASL Weekend</html:radio></td>
			<th><bean:message key="registration.dayRegistered"/>: </th>
			<td>
				<html:radio property="registration.dayRegistered" value="1">Friday</html:radio><br/>
				<html:radio property="registration.dayRegistered" value="2">Saturday</html:radio><br/>
				<html:radio property="registration.dayRegistered" value="3">Sunday</html:radio><br/>
			</td>
		</tr>
		<tr>
			<th><bean:message key="registration.initialCost"/></th>
			<td><html:text property="registration.cost"/></td>
			<th><bean:message key="registration.offsetCost"/></th>
			<td><html:text property="registration.costOffset"/></td>
		</tr>
		<tr>
			<th><bean:message key="registration.amountPaid"/></th>
			<td><html:text property="registration.paid"/></td>
			<th><bean:message key="registration.status"/></th>
			<td><html:radio property="registration.status" value="1">Submitted</html:radio><br/><html:radio property="registration.status" value="2">Review</html:radio><br/><html:radio property="registration.status" value="3">Approved</html:radio><br/><html:radio property="registration.status" value="4">Rejected</html:radio></td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td><html:submit>Save</html:submit></td>
		</tr>
	</table>
</html:form>
<span id="eventList" name="eventList">
	<c:forEach var="regEvent" items="${regEvents}">
	${regEvent.event.slotName } - ${regEvent.event.eventName} <a href="#" onClick="retrieveURL('/wwadmin/registeredEvent.do?method=delete&amp;registeredEvent.registeredEventID=${regEvent.regEventID}&amp;conID=${regEvent.conID }&amp;regID=${regEvent.regID }', '');return false;">Remove </a><br/>
	</c:forEach>
</span>
<c:choose>
	<c:when test="${registrationID != null && registrationID != '' && registrationID != '0'}">
		<html:form action="/wwadmin/registeredEvent">
			<input type="hidden" name="method" value="save"/>
			<input type="hidden" name="registeredEvent.conID" value="${conID }"/>
			<input type="hidden" name="registeredEvent.regID" value="${registrationID }"/>
			<input type="hidden" name="registeredEvent.status" value="3"/>
			<input type="hidden" name="registeredEvent.userID" value="${userID }"/>
			<input type="hidden" name="registeredEvent.eventID" id="registeredEvent.eventID" value="0" />
			<select name="eventListIDs" id="eventListIDs">
				<c:forEach var="event" items="${events }">
					<option value="${event.eventID};${event.totalSeats }-${event.reservedSeats }">${event.slotName} - ${event.eventName} (${event.reservedSeats } / ${event.totalSeats })</option>
				</c:forEach>
			</select>
			<input type="button" value="Add Event" onclick="verifySlotFull()"/>
		</html:form>
	</c:when>
</c:choose>
<script type="text/javascript">
function verifySlotFull(){
	list = document.getElementById("eventListIDs");

	if((list.value.split(";")[1].split("-")[0]-0) <= (list.value.split(";")[1].split("-")[1]-0)){
		if(confirm("WARNING! Adding this event will cause it to be overfiled!  Continue?")){
			document.getElementById("registeredEvent.eventID").value = list.value.split(";")[0];
			retrieveURL('/wwadmin/registeredEvent.do', 'registeredEventForm');
		}
	} else {
		document.getElementById("registeredEvent.eventID").value = list.value.split(";")[0];
		retrieveURL('/wwadmin/registeredEvent.do', 'registeredEventForm');
	}
}
</script>